Return to start page

Core/Maths/Struct Circle.j

Code

		
1			library AStructCoreMathsCircle requires AStructCoreMathsPoint, ALibraryCoreMathsPoint
2
3 struct ACircle extends APoint
4 //dynamic members
5 private real m_radius
6
7 //dynamic members
8
9 public method setRadius takes real radius returns nothing
10 set this.m_radius = radius
11 endmethod
12
13 public method radius takes nothing returns real
14 return this.m_radius
15 endmethod
16
17 //methods
18
19 public method diameter takes nothing returns real
20 return 2 * this.m_radius
21 endmethod
22
23 public method area takes nothing returns real
24 return Pow(this.m_radius, 2.0) * bj_PI
25 endmethod
26
27 public method containsPoint takes real x, real y returns boolean
28 return (GetDistanceBetweenPoints(x, y, 0.0, this.x(), this.y(), 0.0) <= this.m_radius)
29 endmethod
30
31 //instead of x() and y() it has to be a protected element
32 //but there is no protected keyword...
33 public method borderContainsPoint takes real x, real y returns boolean
34 return (GetDistanceBetweenPoints(x, y, 0.0, this.x(), this.y(), 0.0) == this.m_radius)
35 endmethod
36
37 //! textmacro ACircleMacro takes TYPE, TYPENAME
38 public method contains$TYPENAME$ takes $TYPE$ circle$TYPENAME$ returns boolean
39 return this.containsPoint(Get$TYPENAME$X(circle$TYPENAME$), Get$TYPENAME$Y(circle$TYPENAME$)) //Because of the location type I use the 'Circle' prefix
40 endmethod
41
42 public method borderContains$TYPENAME$ takes $TYPE$ circle$TYPENAME$ returns boolean
43 return this.borderContainsPoint(Get$TYPENAME$X(circle$TYPENAME$), Get$TYPENAME$Y(circle$TYPENAME$))
44 endmethod
45 //! endtextmacro
46
47 //! runtextmacro ACircleMacro("location", "Location")
48 //! runtextmacro ACircleMacro("widget", "Widget")
49 //! runtextmacro ACircleMacro("unit", "Unit")
50 //! runtextmacro ACircleMacro("destructable", "Destructable")
51 //! runtextmacro ACircleMacro("item", "Item")
52
53 public method borderLocation takes real angle returns location
54 return GetPolarProjectionOfPoint(this.x(), this.y(), angle, this.m_radius)
55 endmethod
56
57 public method randomLocation takes nothing returns location
58 local real distance = (SquareRoot(GetRandomReal(0.0, 1.0)) * this.m_radius)
59 local real angle = GetRandomReal(0.0, (2.0 * bj_PI))
60 return Location((this.x() + (distance * Cos(angle))), (this.y() + (distance * Sin(angle))))
61 endmethod
62
63 /// @return Added special effect.
64 public method addSpecialEffect takes string modelName, real angle, real distance returns effect
65 return AddSpecialEffect(modelName, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance))
66 endmethod
67
68 /// @return Added spell effect.
69 public method addSpellEffect takes string abilityString, effecttype effectType, real angle, real distance returns effect
70 return AddSpellEffect(abilityString, effectType, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance))
71 endmethod
72
73 /// @return Added spell effect.
74 public method addSpellEffectById takes integer abilityId, effecttype effectType, real angle, real distance returns effect
75 return AddSpellEffectById(abilityId, effectType, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance))
76 endmethod
77
78 /// @return Created unit.
79 public method createUnit takes player user, integer unitType, real angle, real distance, real face returns unit
80 return CreateUnit(user, unitType, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance), face)
81 endmethod
82
83 /// @return Created destructable.
84 public method createDestructable takes integer destructableType, real angle, real distance, real face, real scale, integer variation returns destructable
85 return CreateDestructable(destructableType, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance), face, scale, variation)
86 endmethod
87
88 /// @return Created destructable.
89 public method createDestructableZ takes integer destructableType, real angle, real distance, real z, real face, real scale, integer variation returns destructable
90 return CreateDestructableZ(destructableType, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance), z, face, scale, variation)
91 endmethod
92
93 /// @return Created item.
94 public method createItem takes integer itemType, real angle, real distance returns item
95 return CreateItem(itemType, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance))
96 endmethod
97
98 /// @return Created trackable.
99 public method createTrackable takes string modelPath, real angle, real distance, real facing returns trackable
100 return CreateTrackable(modelPath, this.polarProjectionX(angle, distance), this.polarProjectionY(angle, distance), facing)
101 endmethod
102
103 public static method create takes real x, real y, real radius returns thistype
104 local thistype this = thistype.allocate(x, y)
105 //dynamic members
106 set this.m_radius = radius
107
108 return this
109 endmethod
110 endstruct
111
112 endlibrary